#!/bin/bash

chown='/bin/chown'
chmod='/bin/chmod'
apache_group='apachetwm'
find='/usr/bin/find'
grep='/bin/grep'
SQUID_CONF='/etc/squid/squid.conf'
SQUIDGUARD_CONF='/etc/squidguard.conf'

echo -n "Setting appropriate file permissions                .......... "

    cd $TWMFOLDER
    $chown -R root:$apache_group ./
	$chmod 640 `$find . -type f|$grep -v 'apache/bin'|$grep -v '/http_top/logs'|$grep -v '/http_logging/logs'|$grep -v 'tcp_logging/logs/'|$grep -v 'if_meter/logs'`
    $chmod 750 `$find . -type d`
    $chmod 750 `$find . -name \*.sh`
    $chmod 750 `$find . -name \*.pl`
    $chmod 660 `$find . -name \*.xml`
    $chmod 660 `$find . -name \*.conf`
    $chmod 640 `$find . -name \*.pm`
    $chmod 770 $TWMFOLDER/backup
    $chmod -R g+w $TWMFOLDER/logs
    $chmod -R g+w $TWMFOLDER/etc/passwd
    $chmod 4750 ./bin/runner
    $chmod 4750 ./bin/forker
    $chown root:$apache_group "/usr/local/twm/template/kernel/scand.ca"
    $chown root:$apache_group "/usr/local/twm/template/kernel/scand.lan"
    $chmod 664 "/usr/local/twm/template/kernel/scand.ca"
    $chmod 664 "/usr/local/twm/template/kernel/scand.lan"
    $chmod 770 ./modules/shaping_cbq/cbq

# module customization
    $chmod 750 "$TWMFOLDER/modules/http_ip_limit/httpr_sl"
    $chmod 750 "$TWMFOLDER/modules/shaping_cbq/cbq.init"
    $chmod 750 "$TWMFOLDER/modules/if_meter/traff_meter"
    $chmod 664 $SQUID_CONF
    $chown root:$apache_group $SQUID_CONF
    $chmod 664 $SQUIDGUARD_CONF
    $chown root:$apache_group $SQUIDGUARD_CONF
    $chmod 770 /etc/squid/delay
    $chown root:$apache_group /etc/squid/delay


echo -e "\E[32mok\033[0m"

exit 0
